package cn.xiaobai.core.service.impl;

import cn.xiaobai.core.domain.config.ToolInfo;
import cn.xiaobai.core.domain.dto.ToolInfoDTO;
import cn.xiaobai.core.mapper.DataToDTOMapper;
import cn.xiaobai.core.service.ToolManager;
import cn.xiaobai.core.service.ToolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @Author yangdaji
 * @Date 2023/12/11
 * @PackageName cn.xiaobai.core.service
 * @ClassName ToolService
 */
@Service
public class ToolServiceImpl implements ToolService {

    @Autowired
    private ToolManager toolManager;

    @Override
    public List<ToolInfoDTO> getAllToolInfo() {
        return DataToDTOMapper.mapper.convertToAllToolInfoDto(toolManager.getToolInfos());
    }

    @Override
    public ToolInfoDTO getToolInfo(Integer id) {
        List<ToolInfo> toolInfos = toolManager.getToolInfos();
        return DataToDTOMapper.mapper.convertToToolInfoDto(toolInfos.stream()
                .filter(info -> Objects.equals(id, info.getId()))
                .findAny().orElse(null));
    }
}
